package com.ruoyi.project.personal.signature.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.utils.SecurityUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.personal.signature.domain.UserSignature;
import com.ruoyi.project.personal.signature.service.IUserSignatureService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 个性签名Controller
 * 
 * @author wyh
 * @date 2024-06-16
 */
@RestController
@RequestMapping("/personal/signature")
public class UserSignatureController extends BaseController
{
    @Autowired
    private IUserSignatureService userSignatureService;

    /**
     * 查询个性签名列表
     */
    @PreAuthorize("@ss.hasPermi('personal:signature:list')")
    @GetMapping("/list")
    public TableDataInfo list(UserSignature userSignature)
    {
        //非管理部门限制用户只能查看本部门提交的申请
        Long deptId = SecurityUtils.getDeptId();
        if(deptId != 103L){
            userSignature.setTopInviterId(SecurityUtils.getUserId());
        }

        startPage();
        List<UserSignature> list = userSignatureService.selectUserSignatureList(userSignature);
        return getDataTable(list);
    }

    /**
     * 导出个性签名列表
     */
    @PreAuthorize("@ss.hasPermi('personal:signature:export')")
    @Log(title = "个性签名", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, UserSignature userSignature)
    {
        List<UserSignature> list = userSignatureService.selectUserSignatureList(userSignature);
        ExcelUtil<UserSignature> util = new ExcelUtil<UserSignature>(UserSignature.class);
        util.exportExcel(response, list, "个性签名数据");
    }

    /**
     * 获取个性签名详细信息
     */
    @PreAuthorize("@ss.hasPermi('personal:signature:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(userSignatureService.selectUserSignatureById(id));
    }

    /**
     * 新增个性签名
     */
    @PreAuthorize("@ss.hasPermi('personal:signature:add')")
    @Log(title = "个性签名", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody UserSignature userSignature)
    {
        return toAjax(userSignatureService.insertUserSignature(userSignature));
    }

    /**
     * 修改个性签名
     */
    @PreAuthorize("@ss.hasPermi('personal:signature:edit')")
    @Log(title = "个性签名", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody UserSignature userSignature)
    {
        return toAjax(userSignatureService.updateUserSignature(userSignature));
    }

    /**
     * 删除个性签名
     */
    @PreAuthorize("@ss.hasPermi('personal:signature:remove')")
    @Log(title = "个性签名", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(userSignatureService.deleteUserSignatureByIds(ids));
    }
}
